package com.lbw.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lbw.entity.SubjectEntity;
import com.lbw.result.Result;
import com.lbw.result.ResultFactory;
import com.lbw.service.SubjectEntityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  科目控制器   前端控制器
 * </p>
 *
 * @author lbw
 * @since 2020-09-26
 */
@RestController
@RequestMapping("/subjectEntity")
@Api(tags = "科目")
public class SubjectEntityController {

    @Autowired
    private SubjectEntityService subjectEntityService;

    /**
     * 根据学生id获取所有科目信息
     * @return
     */
    @GetMapping("selectSubject")
    @ApiOperation("获取所有科目信息")
    public Result selectSubject(@ApiParam("学生id") @RequestParam("stuId") String stuId) {
        LambdaQueryWrapper<SubjectEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SubjectEntity::getStuId,stuId);
        List<SubjectEntity> entityList = subjectEntityService.list(lambdaQueryWrapper);
        if (entityList != null && !entityList.isEmpty()) {
            return ResultFactory.success(entityList);
        }
        return ResultFactory.fail("暂无科目！");
    }

}

